package com.example.demo.config;

import com.example.demo.interceptor.CorsInterceptor;
import com.example.demo.interceptor.LoginInterceptor;
import com.example.demo.utils.TokenUtil;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.annotation.Resource;

@Configuration
public class WebConfig implements WebMvcConfigurer {
    @Resource
    public TokenUtil tokenUtil;
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new CorsInterceptor()).addPathPatterns("/**");
        registry.addInterceptor(new LoginInterceptor(tokenUtil)).addPathPatterns("")
                .excludePathPatterns("/user/log")
                .excludePathPatterns("/swagger-resources/**", "/webjars/**", "/v2/**", "/swagger-ui/**","/");
    }
}
